﻿@using Coldairarrow.Business.Base_SysManage;

@{
    var permissions = PermissionManage.GetUserPermissionModules((string)ViewData["userId"]);
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>PermissionForm3</title>
    <link rel="stylesheet" type="text/css" href="@Url.Scrpit("~/Scripts/vendor/bootstrap/css/bootstrap.min.css")">
    <link rel="stylesheet" type="text/css" href="@Url.Scrpit("~/Scripts/vendor/font-awesome/css/font-awesome.min.css")">
    <link rel="stylesheet" type="text/css" href="@Url.Scrpit("~/css/fx/permisson-form.css")" />

    <script src="~/Scripts/vendor/jQuery/jquery-2.2.3.min.js"></script>
    <script src="~/Scripts/util/util.js"></script>
    <script src="~/Scripts/vendor/layer/layer.js"></script>
    <script src="~/Scripts/vendor/layer/layer-extends.js"></script>
</head>
<body>
    <div style="padding:15px;padding-right:45px;">
        <form id="form" class="form-horizontal" role="form">
            <div class="form-group form-group-sm">
                <label class="col-sm-1 control-label">模块</label>
                <label class="col-sm-10 control-label" style="text-align:left">权限项</label>
            </div>
            @foreach (var aModule in permissions)
            {
                <div class="form-group form-group-sm">
                    <label class="col-sm-1 control-label">@aModule.Name</label>
                    <div class="col-sm-9">
                        @foreach (var item in aModule.Items)
                        {
                            <div class="checkbox checkbox-success checkbox-inline">
                                <input type="checkbox" class="styled" id="@item.Id" @(item.IsChecked ? "checked" : "") value="@item.Value">
                                <label for="@item.Id">@item.Name</label>
                            </div>
                        }
                    </div>
                    <div class="col-sm-2">
                        <div class="btn-group btn-group-sm">
                            <button onclick="selectAll(this);" type="button" class="btn btn-success">全选</button>
                            <button onclick="unSelectAll(this);" type="button" class="btn btn-default">取消</button>
                        </div>
                    </div>
                </div>
            }
        </form>
    </div>

    <script>
        var userId = request('userId');

        function selectAll(btnObj) {
            $(btnObj).parent().parent().parent().find('input').each(function (index, item) {
                $(item).prop('checked', 'checked');
            });
        }

        function unSelectAll(btnObj) {
            $(btnObj).parent().parent().parent().find('input').each(function (index, item) {
                $(item).removeAttr('checked');
            });
        }

        function savePermission() {
            var permissions = [];
            $('input:checked').each(function (index, item) {
                permissions.push($(item).attr('value'));
            });

            $.postJSON('/Base_SysManage/Base_User/SavePermission', {
                userId: userId,
                permissions: JSON.stringify(permissions)
            }, function (resJson) {
                if (resJson.Success) {
                    dialogSuccess('保存成功!');
                }
                else {
                    dialogError(resJson.Msg);
                }
            });
        }
    </script>
</body>
</html>
